(function ($) {

AjaxSolr.TextWidget = AjaxSolr.AbstractFacetWidget.extend({
  appendix : '',
  init: function () {
    var self = this;
    $(this.target).find('#text').bind('keydown', function(e) {
      if (e.which == 13) {
        $(this.target).find('#button').click();
      }
    });
    $(this.target).find('#button').bind('click', function(e) {
        var value = $(this.target).find('#text').val();
        if(value=="") {alert('Please enter query string!');return;}
        self.manager.store.addByValue('q', '(+'+value+'+)'+self.appendix);
        self.manager.doRequest(0);
    });
    $(this.target).find('#reset').bind('click', function(e) {
        var loc = window.location.href.slice(0,window.location.href.indexOf('?')+1);
        if(loc.indexOf("?") != -1)loc=window.location.href.slice(0,window.location.href.indexOf('?'));
        window.location.href = loc;
        $(this.target).find('#text').val('');
    });
  }
});

})(jQuery);